<?php

defined('BASEPATH') or die('forbidden');

class Feedback_Controller Extends Controller {
    private $m;	//数据库连接
    private $server_info;
	
    function _init() {
        check_level(50, segment(0), segment(1));
        set_time_limit(0);

        //得到选择的区号
		$areanum = $_SESSION['area_selected_id'];
        if ($areanum == '') 
        {
            echo "<script>alert('" . translate('C_SELECT_AREA_TEXT') . "');</script>";
            return;
        }

        //query server mapping
        $selectSql = "SELECT * FROM server_mapping WHERE dbtype='1' AND areanum={$areanum} ";
        $this->db->query($selectSql);
        $this->server_info=$this->db->get_array('default');


        ini_set('mongo.long_as_object', 1);
        // db数据库
        //$this->m = new MongoClient("mongodb://{$this->server_info['username']}:{$this->server_info['userpwd']}@{$this->server_info['dbip']}");
        $this->m = new MongoClient("mongodb://{$this->server_info['dbip']}");
    }

    function index() {
        $this->view->display("seal/feedback/index");
    }

    function flexigrid() {

        list($colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page) = $this->common->get_flexigrid_params();

        $query=$_POST['query'];
        $query_type=$_POST['qtype'];
        if($query_type=='_id'){
            $filter=array($query_type=>(float)$query);
        }else{
            $filter=array($query_type=>$query);
        }
        $collection=$this->m->{$this->server_info['dbname']}->G_FeedBack;
        if($query!=''){
            $document=$collection->find($filter);
        }else{
            $document=$collection->find();
        }
        $data=array();
        $total = count($document);

        foreach ($document as $key=>$value){
            $value['_id'] = (String)$value['_id'];
            $value['playerid'] = (String)$value['playerid'];
            $data[$key]=array('id' => $value['_id'], 'cell' => $value);
        }

        $result = array(
            'page' => $page,
            'total' => $total,
            'rows' => $data
        );

        echo json_encode($result);
    }

}

?>